package com.ruoyi.edu.controller;

import java.util.List;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.edu.domain.Copyright;
import com.ruoyi.edu.service.ICopyrightService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 软著Controller
 * 
 * @author sanda
 * @date 2024-12-30
 */
@RestController
@RequestMapping("/edu/copyright")
public class CopyrightController extends BaseController
{
    @Autowired
    private ICopyrightService copyrightService;

    /**
     * 查询软著列表
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:list')")
    @GetMapping("/list")
    public TableDataInfo list(Copyright copyright)
    {
        startPage();
        List<Copyright> list = copyrightService.selectCopyrightList(copyright);
        return getDataTable(list);
    }

    /**
     * 导出软著列表
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:export')")
    @Log(title = "软著", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(Copyright copyright)
    {
        List<Copyright> list = copyrightService.selectCopyrightList(copyright);
        ExcelUtil<Copyright> util = new ExcelUtil<Copyright>(Copyright.class);
        return util.exportExcel(list, "软著数据");
    }

    /**
     * 获取软著详细信息
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:query')")
    @GetMapping(value = "/{copyrightId}")
    public AjaxResult getInfo(@PathVariable("copyrightId") Long copyrightId)
    {
        return AjaxResult.success(copyrightService.selectCopyrightByCopyrightId(copyrightId));
    }

    /**
     * 新增软著
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:add')")
    @Log(title = "软著", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Copyright copyright)
    {
        return toAjax(copyrightService.insertCopyright(copyright));
    }

    /**
     * 修改软著
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:edit')")
    @Log(title = "软著", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Copyright copyright)
    {
        return toAjax(copyrightService.updateCopyright(copyright));
    }

    /**
     * 删除软著
     */
    @PreAuthorize("@ss.hasPermi('edu:copyright:remove')")
    @Log(title = "软著", businessType = BusinessType.DELETE)
	@DeleteMapping("/{copyrightIds}")
    public AjaxResult remove(@PathVariable Long[] copyrightIds)
    {
        return toAjax(copyrightService.deleteCopyrightByCopyrightIds(copyrightIds));
    }
}
